Copyright: Copyright © 1997, Applied Analytic Systems
Citation: Copyright © 1997, Applied Analytic Systems


SLR Unit

Components

TSLRQuery

TSLRTable


 TSLRTable Component

Properties	Methods	Tasks

Unit

SLR

Description

The TSLRTable component is designed to allow the user to perform Simple Linear Regression on any pair of (numeric) datafields in any table accessible with Delphi's TTable component.  The TSLRTable is used in place of the TTable.  At design time, the developer can use the Object Inspector to specify the database table of interest, and the fields to be used as the Control (independent) variable and Response (dependent) variable.

Through code, the developer can allow end-users to choose their datasets and control/response variables.

In addition to the properties and methods described herein, the TSLRTable possesses all properties and methods of the TTable component.


SLRTSLRTable_Properties_Popup
Properties

 Run-time only	 Key properties

		b0			RSquared			xMax
		b1			SSE			xMin
		ControlVarField			SSR			y
		DegreesOfFreedom			SST			yBar
		e			syx			yHat
		n			t			yMax
		Regressed			x			yMin
		ResponseVarField			xBar


Residual vs input order
Clicking this button plots the residual values e against the order in which the values were input (ordered in the database).  This button is not active until regression has been completed.


SLRTSLRQuery_Properties_Popup
Properties

 Run-time only	 Key properties

		b0			RSquared			xMax
		b1			SSE			xMin
		ControlVarField			SSR			y
		DegreesOfFreedom			SST			yBar
		e			syx			yHat
		n			t			yMax
		Regressed			x			yMin
		ResponseVarField			xBar


SLRTSLRTable_Methods_Popup

Methods

 Key methods

		LoadValues			Predict			ShowPlots


x property

Applies to

TSLRQuery

TSLRTable

Declaration

property x[Index: word]: double;

Description

This is a read only property.  x is a multivalued property which contains all values of the ControlVarField in the regression dataset after the LoadValues method has been executed.

Along with the y property, x can be used to create a scatter plot of the data to look for data trends and outlying datapoints.


y Property

Applies to

TSLRQuery

TSLRTable

Declaration

property y[Index: word]: double;

Description

This is a read only property.  y is a multivalued property which contains all values of the ResponseVarField in the regression dataset after the LoadValues method has been executed.

Along with the x property, y can be used to create a scatter plot of the data to look for data trends and outlying datapoints.


e property

Applies to

TSLRQuery

TSLRTable

Declaration

property e[Index: word]: double;

Description

This is a read-only property.  e is a multi-valued property which contains the residual values y[i] - yhat[i] for each regression point after the actual regression has been run.  In this context, yHat[i] is the fitted value given by the regression equation using the minimal biased estimators.

e may be used to plot residual data.  Using x,y, and yHat, e can be plotted against input order, independent variable, dependent variable, or fitted y.


yHat property

Applies to

TSLRQuery

TSLRTable

Declaration

property yHat[Index: word]: double;

Description

This is a read-only property.  yHat is a multivalued-property containing all values of the fitted function y = b0 + b1x after the regression has been run.

The fitted values yHat[i] are the best estimators of the response variables y[i].


xBar property

Applies to

TSLRQuery

TSLRTable

Declaration

property xBar: double;

Description

This is a read-only property, calculated from the data contained in the ControlVarField of the dataset under study.  xBar is the mathematical sample average of this data:

xBar = (x[1] + x[2] + ... + x[n])/n


yBar property

Applies to

TSLRQuery

TSLRTable

Declaration

property yBar: double;

Description

This is a read-only property, calculated from the data contained in the ResponseVarField of the dataset under study.  yBar is the mathematical sample average of this data.  If there are n datapoints, then:

yBar = (y[1] + y[2] + ... + y[n])/n


xMax property

Applies to

TSLRQuery

TSLRTable

Declaration

property xMax: double;

Description

This is a read-only property.  xMax is the largest value in the ControlVarField of the dataset, computed when the LoadValues method is executed.

xMax = maximum{x[i]: 1<= i <= n}


yMax property

Applies to

TSLRQuery

TSLRTable

Declaration

property yMax: double;

Description

This is a read-only property.  yMax is the largest value in the ResponseVarField of the dataset, computed when the LoadValues method is executed.

yMax = maximum{y[j]: 1<= j <= n}


xMin property

Applies to

TSLRQuery

TSLRTable

Declaration

property xMin: double;

Description

This is a read-only property.  xMin is the smallest value in the ControlVarField of the dataset, computed when the LoadValues method is executed.

xMin = minimum{x[i]: 1<= i <= n}


yMin property

Applies to

TSLRQuery

TSLRTable

Declaration

property yMin: double;

Description

This is a read-only property.  yMin is the smallest value in the ResponseVarField of the dataset, computed when the LoadValues method is executed.

yMin = minimum{y[j]: 1<= j <= n}


b0 property

Applies to

TSLRQuery

TSLRTable

Declaration

property b0: double;

Description

This is a read-only property.  b0 is computed during the regression process, and is the minimum-variance, unbiased estimator of B0 in the theoretical model

y = B0 + B1x


b1 property

Applies to

TSLRQuery

TSLRTable

Declaration

property b1: double;

Description

This is a read-only property.  b1 is computed during the regression process, and is the minimum-variance, unbiased estimator of B1 in the theoretical model

y = B0 + B1x


SSR property

Applies to

TSLRQuery

TSLRTable

Declaration

property SSR: double;

Description

This is a read-only property.  SSR is calculated during regression.  It is the sum-of-squares due to the regression,

SSR = (yHat[1]-yBar)^2 + (yHat[2]-yBar)^2 +...+ (yHat[n]-yBar)^2

An additional quantity, SSE, is calculated from SST and SSR.  SSE is the sum of squares of the residuals.  Mathematically,

SSE = (y[1]-yHat[1])^2 + (y[2]-yHat[2])^2 +...+ (y[n]-yHat[n])^2

or

SSE = SST - SSR


SST property

Applies to

TSLRQuery

TSLRTable

Declaration

property SST: double;

Description

This is a read-only property.  SST is calculated during regression.  It is known as the total sum-of-squares,

SST = (y[1]-yBar)^2 + (y[2]-yBar)^2 +...+ (y[n]-yBar)^2

An additional quantity, SSE, is calculated from SST and SSR.  SSE is the sum of squares of the residuals.  Mathematically,

SSE = (y[1]-yHat[1])^2 + (y[2]-yHat[2])^2 +...+ (y[n]-yHat[n])^2

or

SSE = SST - SSR


RSquared property

Applies to

TSLRQuery

TSLRTable

Declaration

property RSquared: double;

Description

This is a read-only property.  RSquared is calculated from the regression, and is known as the multiple correlation coefficient squared.

RSquared = SSR/SST

RSquared represents the proportion of the total sum-of-squares which is explained by the SLR model.


syx property

Applies to

TSLRQuery

TSLRTable

Declaration

property syx: double;

Description

This is a read-only property.  syx is the square root of the sample variance s^2y|x.  s^2y|x is the conditional value of the sample variance of y,  given knowledge of the associated paired values of x.  It is calculated when a confidence interval on the fitted line is requested, and is the best estimate of the true, but unknown value of sigma-squared.  s^2y|x and syx have n-2 degrees of freedom,

s^2y|x = SSE/(n-2)

and

syx = [SSE/(n-2)]^1/2


DegreesOfFreedom property

Applies to

TSLRQuery

TSLRTable

Declaration

property DegreesOfFreedom: word;

Description

This is a read-only property. This is calculated when values are loaded into memory using the LoadValues method.  DegreesOfFreedom refers to that used to calculate the syx value, and the corresponding t-statistic value.  If the dataset contains n datapoints, then

DegreesOfFreedom = n-2


Regressed property

Applies to

TSLRQuery

TSLRTable

Declaration

property Regressed: Boolean;

Description

This is a read-only property.  This property indicates whether or not the regression has been run, and consequently all values have been calculated.


ControlVarField property

Applies to

TSLRQuery

TSLRTable

Declaration

property ControlVarField: string;

Description

This is a read-write property.  The ControlVarField is designated by the developer (or end-user) as the datafield containing the values of the independent variable for the proposed SLR model.  This value can be set through code, or through the Object Inspector.

When using the TSLRTable component, the developer can set the DatabaseName and TableName properties in the Object Inspector, and set the Active property to True.  The table datafields which are available for use as a Control Variable can then be chosen from a drop-down list (which contains only the names of the numeric fields in the database table).

When using the TSLRQuery component, the developer can set the DatabaseName property in the Object Inspector, input the query, and set the Active property to True.

When specifying the fields to be used in the regression (setting the ControlVarField and ResponseVarField properties), the developer must be careful to specify only numeric fields; otherwise, run-time errors will occur.


ResponseVarField property

Applies to

TSLRQuery

TSLRTable

Declaration

property ResponseVarField: string;

Description

This is a read-write property.  The ResponseVarField is designated by the developer (or end-user) as the datafield containing the values of the dependent variable for the proposed SLR model.  This value can be set through code, or through the Object Inspector.

When using the TSLRTable component, the developer can set the DatabaseName and TableName properties in the Object Inspector, and set the Active property to True.  The table datafields which are available for use as a Response Variable can then be chosen from a drop-down list (which contains only the names of the numeric fields in the database table).

When using the TSLRQuery component, the developer can set the DatabaseName property in the Object Inspector, input the query, and set the Active property to True.

When specifying the fields to be used in the regression (setting the ControlVarField and ResponseVarField properties), the developer must be careful to specify only numeric fields; otherwise, run-time errors will occur.


t property

Applies to

TSLRQuery

TSLRTable

Declaration

property t: double;

Description

This is a read-write property.  t can be set by the developer in the Object Inspector and/or through code by the end-user.  In practice, t should be read from a table of t-statistics, corresponding to the degrees-of-freedom for the dataset.

The value of t is used to test the hypotheses:

H0: There is no significant relationship between x and y

HA: There is a significant relationship between x and y

and to construct confidence intervals on the predicted value of y.


LoadValues method

Applies To

TSLRQuery

TSLRTable

Declaration

procedure LoadValues;

Description

The LoadValues method loads the values from the user-defined ControlVarField and ResponseVarField fields into memory for future processing.  Once loaded, scatter plots of the data can be viewed immediately.


ShowPlots method

Applies To

TSLRQuery

TSLRTable

Declaration

procedure ShowPlots;

Description

The ShowPlots method opens a modal dialog box on which the plots of the data can be viewed.  Available plots are

   Scatter Plot of the Data (Dependent vs Independent Variable)

   Plot of Residuals vs.

 Input Order

 Independent Variable

 Dependent Variable

 Fitted Values

   Fitted Line

   Confidence Band on Fitted Line


Predict method

Applies To

TSLRQuery

TSLRTable

Declaration

function Predict(x: double): double;

Description

The Predict function returns the predicted value of the dependent variable (y) given a value representing the independent variable (x), according to the formula

y = b0 + b1x

where b0 and b1 are the minimum unbiased estimators calculated from the regression.


 TSLRQuery Component

Properties	Methods	Tasks

Unit

SLR

Description

The TSLRQuery component is designed to allow the user to perform Simple Linear Regression on any pair of (numeric) datafields in any group of tables accessible with Delphi's TQuery component.  The TSLRQuery is used in place of the TQuery.  At design time, the developer can use the Object Inspector to specify the database of interest, and the fields to be used as the Control (independent) variable and Response (dependent) variable.

Through code, the developer can allow end-users to choose their datasets and control/response variables.

In addition to the properties and methods described herein, the TSLRQuery possesses all properties and methods of the TQuery component.


SSE Property

Applies to

TSLRQuery

TSLRTable

Declaration

property SSE: double;

Description

This is a read-only property.  SSE, is calculated from SST and SSR.  SSE is the sum of squares of the residuals.  Mathematically,

SSE = (y[1]-yHat[1])^2 + (y[2]-yHat[2])^2 +...+ (y[n]-yHat[n])^2

or

SSE = SST - SSR


SLRTSLRQuery_Methods_Popup
Methods

 Key methods

		LoadValues			Predict			ShowPlots


Scatter Plot
Clicking this button shows a scatter plot of the [x(i),y(i)] pairs, plotted in the x,y coordinate plane.  Scatter plots can be viewed anytime subsequent to execution of the LoadValues method.


  Using the SLRQuery Component

See Also	TQuery Reference in Delphi Help

Purpose

Use the SLRQuery component to provide SQL statements that retrieve data from one or more physical database tables.  Numeric data retrieved from tables can be regressed upon using the Predict function, or by accessing any property which requires regression for its computation.

Users can view data retrieved by the SLRQuery component in a data-aware component.

Use the DataSource to connect an SLRQuery and a data-aware component.

For basic background information on the ancestor Query component, see Overview of TQuery Component in Delphi Help.

Connecting to Databases

 To specify the database that contains the physical table with which

    to work, see Specifying a Database Name or Alias in Delphi Help.

 To connect an SLRQuery component to a physical table, see

    Specifying a Dataset in Delphi Help.

 To connect your application to a physical database, see Overview

    of Connecting to Databases in Delphi Help.


Residual vs Independent Variable
Clicking this button plots the residual values e[i] against the independent variable values x[i] retrieved from the  database.  This button is not active until regression has been completed.


  Using the SLRTable Component

See Also	TTable Reference in Delphi Help

Purpose

Use the SLRTable component to retrieve data from a physical database table (and

send data back to a physical database table).  Numeric data retrieved from the table can be regressed upon using the Predict function, or by accessing any property which requires regression for its computation.

Users view data retrieved by the SLRTable component in a data-aware component.

Use a DataSource to connect a SLRTable and a data-aware component.

For basic background information on the ancestor Table component, see Overview of

TTable Component and TQuery Compared With TTable in Delphi Help.

Connecting to Databases

 To specify the database that contains the physical table with which

    to work, see Specifying a Database Name or Alias in Delphi Help.

 To connect a Table component to a physical table, see Specifying a

    Dataset in Delphi Help.

 To connect your application to a physical database, see Overview of

    Connecting to Databases in Delphi Help.

Accessing Data

 To ensure no other user can access or modify the table while it is open,

    set the Exclusive property to True.

 To prevent modifications to the table, set ReadOnly to True.

 The ReadOnly property cannot be changed while the Active property is

    set to True.

 To create a persistent list of TField objects, see Using the Fields Editor.

 To sort the table on a secondary index, use the IndexName property.

Creating Master-Detail Relationships

 To create a master-detail relationship, specify the data source

    used by the master table in the MasterSource property of the detail.

 To specify the field upon which to link master and detail tables, use the

    MasterFields property to display the  Field Link Designer.

 See Using the Field Link Designer in Delphi Help.


Residuals vs Dependent Variable
Clicking this button plots the residual values e[i] against the dependent variable values y[i] retrieved from the  database.  This button is not active until regression has been completed.


Residual vs Fitted y
Clicking this button plots the residual values e[i] against the fitted variable values yHat[i] calculated from the regression.  This button is not active until regression has been completed.


Clear Plots
Clicking this button clears all plots currently on the canvas so that new plots can be graphed.


Close Plot Form
Clicking this button closes the Plot Form.


Plot Fitted Line
Clicking this button plots the fitted line using the minimal variance unbiased estimators b0 and b1.  This button is not active until regression has been completed.


Plot Confidence Band
Clicking this button plots confidence band on the fitted line using the minimal variance unbiased estimators b0 and b1, the sample variance sy|x, and the current value of the t property.  This button is not active until regression has been completed.


n Property

Applies to

TSLRQuery

TSLRTable

Declaration

property n: word;

Description

This is a read-only property, containing the number of values loaded from the dataset.  This is equivalent to the component's RecordCount property.